<template>
  <div class="homeNav">
    <div class="log">
      <van-icon name="bell" size="20" color="#878" dot></van-icon>
    </div>
    <div class="content">
      <span @click="tab(1)" :class="num===1?'active':''">关注</span>
      <span @click="tab(2)" :class="num===2?'active':''">发现</span>
      <span @click="tab(3)" :class="num===3?'active':''">泸州</span>
    </div>
    <div class="search">
      <van-icon name="search" size="20"></van-icon>
    </div>
  </div>
</template>

<script>
import {ref} from "vue"
export default {
  name : "HomeNav",
  emits:['tab'],
  setup(props,context){
    // home tab栏切换
    let num = ref (2)
    function tab (i) { 
      num.value = i
      // 滚动到app所在的位置（无滚动效果），如app在顶部，即回到顶部
      document.getElementById("app").scrollIntoView();
      context.emit("tab",i)
    }
    
    return {
      num,tab
    }
  }
}
</script>

<style scoped lang="scss">
.homeNav {
  width: 100vw;
  height: 45px;
  padding: 0 3%;
  margin-bottom: 1%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: #fff;
  border-bottom: 1px solid #eee;
  .content {
    width: 50%;
    display: flex;
    justify-content: space-between;
    span {
      font-size: 16px;
      color: #aaa;
    }
    .active {
      color: #000;
      font-weight: bold;
      position: relative;
    }
    .active::before {
      content: "";
      display: block;
      width: 13px;
      position: absolute;
      top: 22px;
      left: 9px;
      border-bottom: 2px solid red;
    }
  }
}
</style>